<include file="Weixin/header" />
<title>开票信息</title>
</head>
<body class="clearfix tkfp">
    <div class="tt">
		<h3>抬头类型</h3>
		<?php if($info['invoice_rise'] == 1){ ?>
		<img src="__PUBLIC__/weixin/images/quan.png" invoice_rise="2" />    单位  
		<img src="__PUBLIC__/weixin/images/quan2.png" invoice_rise="1" />  个人
		<?php }else{ ?>
		<img src="__PUBLIC__/weixin/images/quan2.png" invoice_rise="2" />    单位  
		<img src="__PUBLIC__/weixin/images/quan.png" invoice_rise="1" />  个人
		<?php } ?>
	</div>
    <div class="cont3 leix">
        <h3>发票类型</h3>
        <ul>
            <li class="{$info['invoice_type'] == 1 ? 'select' : ''}" invoice_type="1">普通发票</li>
            <li class="{$info['invoice_type'] == 2 ? 'select' : ''}" invoice_type="2">增值税普通</li>
            <li class="{$info['invoice_type'] == 3 ? 'select' : ''}" invoice_type="3">增值税专用</li>
        </ul>
    </div>
    <div class="card" style="display:block; padding-bottom: 5px;">
        <div class="cont3 form">
            <ul>
                <li>单位名称:  <input type="text" placeholder="请输入单位名称" name="invoice_title" id="invoice_title" value="{$info['invoice_title']}"></li>
				<div class="tp1" style="display:{$info['invoice_type'] >= 2 ? 'block' : 'none'};">
					<li>税号:  <input type="text" placeholder="请输入纳税人识别号" name="invoice_duty" id="invoice_duty" value="{$info['invoice_duty']}"></li>
				</div>
				<div class="tp2" style="display:{$info['invoice_type'] >= 3 ? 'block' : 'none'};">
					<li>单位地址:  <input type="text" placeholder="请输入单位地址" name="address" id="address" value="{$info['address']}"></li>
					<li>电话号码:  <input type="text" placeholder="请输入登记的电话号码" name="phone" id="phone" value="{$info['phone']}"></li>
					<li>开户银行:  <input type="text" placeholder="请输入开户银行名称" name="bank" id="bank" value="{$info['bank']}"></li>
					<li>银行账号:  <input type="text" placeholder="请输入开户的银行账号" name="bankcard" id="bankcard" value="{$info['bankcard']}"></li>
				</div>
            </ul>
        </div>
        <div class="ck"><input type="checkbox" id="is_default" name="is_default" {$info['is_default'] == 1 ? 'checked' : ''}/>设为默认</div>
        <div class="btn" style="margin:0.5rem auto">
			<img src="__PUBLIC__/weixin/images/btn.png" />
			<div class="tex">保存发票</div>
		</div>
    </div>
    <script>
		var invoice_type = "{$info['invoice_type']}" || 1;
		
        $(".leix li").on("touchend",function () { 
            $(".leix li").removeClass("select");
            $(this).addClass("select");
			//设置值
			invoice_type = $(this).attr('invoice_type');
			//显示隐藏div
			var index = $(this).index();
			switch(index/1){
				case 0:
					$("div.tp1,div.tp2").hide();
				break;
				case 1:
					$("div.tp1").show();
					$("div.tp2").hide();
				break;
				case 2:
					$("div.tp1,div.tp2").show();
				break;
			}
        });
		//抬头
		$(".tt img").on("touchend",function () { 
			$(".tt img").attr("src","__PUBLIC__/weixin/images/quan.png");
			$(this).attr("src","__PUBLIC__/weixin/images/quan2.png");
		});
		//提交数据了哦
		$("div.tex").on('click', function(){
			var data = {};
			var invoice_rise = 1;
			$(".tt img").each(function(){
				if($(this).attr('src') == "__PUBLIC__/weixin/images/quan2.png"){
					invoice_rise = $(this).attr('invoice_rise');
				}
			});
			data.invoice_type = invoice_type;
			data.invoice_rise = invoice_rise;
			var invoice_title = $("#invoice_title").val() || "";
			if(invoice_title.length <= 0 || invoice_title.length > 70){
				layer.msg("请正确输入单位名称", {icon: 5, time: 2000});
				return false;
			}else{
				data.invoice_title = invoice_title;
			}
			//判断其余选项
			if(invoice_type/1 > 1){
				//判断税号
				var invoice_duty = $("#invoice_duty").val() || "";
				if(invoice_duty.length <= 0 || invoice_duty.length > 50){
					layer.msg("请正确输入税号", {icon: 5, time: 2000});
					return false;
				}else{
					data.invoice_duty = invoice_duty;
				}
			}
			//判断增值税专票
			if(invoice_type/1 > 2){
				var address = $("#address").val() || "";
				var phone = $("#phone").val() || "";
				var bank = $("#bank").val() || "";
				var bankcard = $("#bankcard").val() || "";
				if(address.length <= 0 || address.length > 100){
					layer.msg("请正确输入地址", {icon: 5, time: 2000});
					return false;
				}else{
					data.address = address;
				}
				
				if(phone.length <= 0 || phone.length > 11){
					layer.msg("请正确输入电话", {icon: 5, time: 2000});
					return false;
				}else{
					data.phone = phone;
				}
				
				if(bank.length <= 0 || bank.length > 100){
					layer.msg("请正确输入开户行", {icon: 5, time: 2000});
					return false;
				}else{
					data.bank = bank;
				}
				
				if(bankcard.length <= 0 || bankcard.length > 100){
					layer.msg("请正确输入银行卡号", {icon: 5, time: 2000});
					return false;
				}else{
					data.bankcard = bankcard;
				}
			}
			data.func = 'kaipiaoinfo';
			data.invoice_id = "{$info['invoice_id']}" || 0;
			
			$.post('ucenter.html', data, function(row){
				if(row){
					layer.msg('保存成功', {icon:1,time:2000}, function(){
						window.location.href = 'ucenter.html?func=kaipiao';
						//window.history.go(-1); 
						//window.location.href = document.referrer;//返回上一页并刷新 
					});
				}else{
					layer.msg('保存失败', {icon:0,time:2000});
				}
			});
		});
    </script>
</body>
</html>